function log(arg) {
    var toPrint = [];
    for (var i = 0; i < arguments.length; ++i) {
        toPrint.push(arguments[i]);
    }

    function getErrorObject(){
        try { throw Error('') } catch(err) { return err; }
    }

    var err = getErrorObject(),
        caller;

    caller = err.stack.split("\n")[3];


    var index = caller.indexOf('.js');

    var str = caller.substr(0, index + 3);
    index = str.lastIndexOf('/');
    str = str.substr(index + 1, str.length);

    var info = "\t\tFile: " + str;

    index = caller.lastIndexOf(':');
    str = caller.substr(0, index);

    index = str.lastIndexOf(':');
    str = str.substr(index + 1, str.length);
    info += " Line: " + str;
    toPrint.push(info);

    console.log.apply(console, toPrint);
}

// log('22aaa');
// window.onerror = function(err) {
//   console.dir(arguments)
//   console.log(err,err.stack);
// };

window.onerror = function (msg, url, lineNo, columnNo, error) {
  console.log(error)
    var string = msg.toLowerCase();
    var substring = "script error";
        var message = [
            'Message: ' + msg,
            'URL: ' + url,
            'Line: ' + lineNo,
            'Column: ' + columnNo,
            'Error object: ' + JSON.stringify(error)
        ].join(' - ');

        console.log(JSON.stringify(arguments),message);

    return false;
};

var a = null;
a.b = 10;
